package com.scm.factory;

import com.scm.common.enums.ProductSourceEnum;
import com.scm.common.utils.AmountUtils;
import com.scm.common.utils.TOTransferHelper;
import com.scm.dto.resp.order.OrderProductDo;
import com.scm.dto.resp.product.ScmProductDetailOmsDo;
import com.scm.dto.resp.product.ScmProductDo;
import com.scm.persist.model.ScmInventoryStashProduct;
import com.scm.persist.model.ScmOrderProduct;
import com.scm.persist.model.ScmProduct;
import com.scm.persist.model.ScmProductDetailOms;
import com.scm.persist.mybatis.ScmProductDetailOmsMapper;
import com.scm.service.IScmInventoryStashProductService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@Component
@Slf4j
public class ProductFactory {


    @Autowired
    private ScmProductDetailOmsMapper scmProductDetailOmsMapper;


    public ScmProductDo createProductDo(ScmProduct product){

        ScmProductDo scmProductDo= new ScmProductDo();
        scmProductDo.setId(product.getId());
        scmProductDo.setTenantId(product.getTenantId());
        scmProductDo.setProductCode(product.getProductCode());
        scmProductDo.setProductName(product.getProductName());
        scmProductDo.setProductUnit(product.getProductUnit());
        scmProductDo.setSource(product.getSource());
        scmProductDo.setBrand(product.getBrand());
        scmProductDo.setRemark(product.getRemark());

        if(ProductSourceEnum.OMS.getCode().equals(product.getSource())){
            ScmProductDetailOms scmProductDetailOms =  scmProductDetailOmsMapper.selectByPid(product.getTenantId(),product.getId());
            scmProductDo.setProductDetailOmsDo(createScmProductDetailOmsDo(scmProductDetailOms));
        }

        return scmProductDo;

    }

    public ScmProductDetailOmsDo createScmProductDetailOmsDo(ScmProductDetailOms scmProductDetailOms ){

        if(scmProductDetailOms==null){
            return new ScmProductDetailOmsDo();
        }
        ScmProductDetailOmsDo productDetailOmsDo= TOTransferHelper.trans2TO(scmProductDetailOms,ScmProductDetailOmsDo.class) ;

        return productDetailOmsDo;
    }


    public static void main(String[] args) {


    }

}
